package com.etoak.utils;

import lombok.Data;

import java.util.List;

/**
 * 通用返回类
 *
 * @author 巫马三及
 */
@Data
public class R {
    private int code = 200;
    private Object data;
    private String msg;
    private boolean isOk;

    public R msg(String msg) {
        this.msg = msg;
        return this;
    }

    public R(boolean isOk) {
        this.code = 200;
        this.msg = "无返回值信息";
        this.isOk = isOk;
    }

    public R(boolean isOk, Object data) {
        this.code = 200;
        this.isOk = isOk;
        this.data = data;
        this.msg = "无返回值信息";
    }

    public R(boolean isOk, Object data, String msg) {
        this.code = 200;
        this.isOk = isOk;
        this.msg = msg;
        this.data = data;
    }

    public R(int code, boolean isOk) {
        this.code = code;
        this.msg = "无返回值信息";
        this.isOk = isOk;
    }

    public R(int code, boolean isOk, Object data) {
        this.code = code;
        this.isOk = isOk;
        this.data = data;
        this.msg = "无返回值信息";
    }

    public R(int code, boolean isOk, Object data, String msg) {
        this.code = code;
        this.isOk = isOk;
        this.msg = msg;
        this.data = data;
    }

    public static R success(Object data) {
        return new R(200, true, data);
    }

    public static R success() {
        return new R(200, true, null);
    }

    public static R error(Object data) {
        return new R(500, true, data);
    }

    public static R error() {
        return new R(500, true, null);
    }
}
